__author__ = 'tonma'

import pyglet
from pyglet.window import key

window = pyglet.window.Window(fullscreen=False )
buffer_number = ""
multiplier = 1
items = []
label = pyglet.text.Label()
temp_text = ""


@window.event
def on_text(text):
    global temp_text
    temp_text = text
    global buffer_number
    try:
        if text.isdigit():
            x = buffer_number + text
            buffer_number = x
    except ValueError:
        pass


@window.event
def on_key_press(symbol, modifier):
    global items
    global buffer_number
    global multiplier
    global label

    if symbol == key.NUM_ADD and buffer_number.isdigit():
        items.append(int(buffer_number) * int(multiplier))
        buffer_number = ""
        multiplier = 1
        print items


    if symbol == key.RETURN:
        total = 0
        for x in items:
            total = total + x
        print "Total de la venta: %s" % (total)
        del items[:]
        items = []
        print items

    if symbol == key.NUM_MULTIPLY and buffer_number.isdigit():
        multiplier = buffer_number
        buffer_number = ""
        print "Multiplier %s" % multiplier

print temp_text
label = pyglet.text.Label(temp_text,
                            font_name='Times New Roman',
                            font_size=36,
                            x=window.width//2, y=window.height//2,
                            anchor_x='center', anchor_y='center')
label.draw()
@window.event
def on_draw():
    window.clear()
    label.draw()

pyglet.app.run()
